package com.thread.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * Java实现多线程的方式3
 * 实现Callable接口，重写call方法
 */
public class StartCallable implements Callable<Integer> {
    @Override
    public Integer call() throws Exception {
        //此处为thread执行的任务内容
        for (int i = 0; i < 200; i++) {
            System.out.println("多线程测试"+i);
        }
        System.out.println(Thread.currentThread().getName());
        return null;
    }

    public static void main(String[] args) {
        //创建StartCallable实例
        Callable<Integer> c = new StartCallable();
        //获取FutureTask
        FutureTask<Integer> ft = new FutureTask<Integer>(c);
        //使用FutureTask初始化Thread
        Thread t = new Thread(ft);
        t.start();
    }

}
